package com.powernode.controller;

/**
 * @version 1.0
 * @Date 2024/8/20 20:21
 * @Author 付~~~
 */

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.powernode.domain.OrdersList;
import com.powernode.model.OrderConfirmParam;
import com.powernode.model.Result;
import com.powernode.service.OrdersListService;
import com.powernode.vo.OrderStatusCount;
import com.powernode.vo.OrderVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * 微信小程序订单业务控制层
 */
@Api("微信小程序订单接口管理")
@RestController
@RequestMapping("p/myOrder")
public class OrderListsController {

    @Autowired
    private OrdersListService ordersListService;

    /**
     * 查询订单各个状态数量
     * @return
     */
    @ApiOperation("查询订单各个状态数量")
    @GetMapping("orderCount")
    public Result<OrderStatusCount> loadMemberStatusCount(){
        OrderStatusCount orderStatusCount = ordersListService.queryMemberOrderStatusCount();
        return Result.success(orderStatusCount);
    }

    //p/myOrder/myOrder?current=1&size=5&status=0

    /**
     * 分页查询会员订单列表
     * @param current 页码
     * @param size 每页显示数
     * @param status 状态:0全部，1待支付，2待发货，3待收货
     * @return
     */
    @ApiOperation("分页查询会员订单列表")
    @GetMapping("myOrder")
    public Result<Page<OrdersList>> loadMemberOrderPage(@RequestParam Long current,
                                                        @RequestParam Long size,
                                                        @RequestParam Long status){

        // 创建分页
        Page<OrdersList> page = ordersListService.queryMemberOrderPage(current,size,status);
        return Result.success(page);
    }

    //orderDetail?orderNumber=1544234268392296448

    /**
     * 根据订单编号查询订单详情信息
     * @param orderNumber 订单编号
     * @return
     */
    @ApiOperation("根据订单编号查询订单详情信息")
    @GetMapping("orderDetail")
    public Result<OrdersList> loadMemberOrderDetail(@RequestParam String orderNumber){
        OrdersList ordersList = ordersListService.queryMemberOrderDetailByOrderNumber(orderNumber);
        return Result.success(ordersList);
    }

    // receipt/1544233812664389632

    /**
     * 会员确认收货
     * @param orderNumber 订单编号
     * @return
     */
    @ApiOperation("会员确认收货")
    @PutMapping("receipt/{orderNumber}")
    public Result<String> receiptMemberOrder(@PathVariable String orderNumber){
        Boolean receipted = ordersListService.receiptMemberOrder(orderNumber);
        return Result.handle(receipted);
    }

    //myOrder/1544233812664389632

    /**
     * 删除已经完成的订单
     * @param orderNumber 订单编号
     * @return
     */
    @ApiOperation("删除已经完成的订单")
    @DeleteMapping("{orderNumber}")
    public Result<String> removeMemberOrder(@PathVariable String orderNumber){
        Boolean removed = ordersListService.removeMemberOrderByOrderNumber(orderNumber);
        return Result.handle(removed);
    }


    //////////////////////////////////// 微信小程序 /////////////////////////////

    // p/myOrder/confirm

    /**
     * 查询会员确认订单页面数据
     * @param orderConfirmParam 订单确认页面参数对象
     * @return
     */
    @ApiOperation("查询会员确认订单页面数据")
    @PostMapping("confirm")
    public Result<OrderVo> loadMemberOrderConfirmVo(@RequestBody OrderConfirmParam orderConfirmParam){
        OrderVo orderVo = ordersListService.queryMemberOrderConfirmVo(orderConfirmParam);
        return Result.success(orderVo);
    }

    /**
     * 会员提交订单
     * @param orderVo 订单确认对象
     * @return
     */
    @ApiOperation("会员提交订单")
    @PostMapping("submit")
    public Result<String> submitOrder(@RequestBody OrderVo orderVo){
        String orderNumber = ordersListService.submitOrder(orderVo);
        return Result.success(orderNumber);
    }
}
